<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.2/dist/echarts.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .main {
            width: 100vw;
            height: 100vh;
        }
    </style>
</head>

<body>
    <div class="main">

    </div>
    <script>
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.querySelector('.main'), 'dark');

        // 指定图表的配置项和数据
        var option = {
            xAxis: {
                type: 'category',
                data: ['Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie']
            },
            yAxis: {},
            series: [{
                    type: 'bar',
                    name: '2015',
                    data: [89.3, 92.1, 94.4, 85.4]
                },
                {
                    type: 'bar',
                    name: '2016',
                    data: [95.8, 89.4, 91.2, 90.9]
                },
                {
                    type: 'bar',
                    name: '2017',
                    data: [97.7, 83.1, 92.5, 78.1]
                }
            ]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);

        function debounce(fun, time) {
            let timer = null;
            return function () {
                if (timer != null) {
                    clearTimeout(timer);
                }
                timer = setTimeout(() => {
                    fun();
                }, time);
            }
        }

        window.onresize = debounce(() => {
            myChart.resize();
        },1000)
    </script>
</body>

</html>